package com.gxa.autoparts.admin.controller;

import com.gxa.autoparts.admin.mapper.OrderMapper;
import com.gxa.autoparts.admin.mapper.UserMapper;
import com.gxa.autoparts.admin.service.UserService;
import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.core.pojo.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.swing.*;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/finance")
@Api
public class FinanceController {
    @Resource
    UserMapper userMapper;
    @Autowired
    UserService userService;
    @Resource
    OrderMapper orderMapper;
    @PostMapping("/selectRecharge")
    @ApiOperation("返回所有的财务信息分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true)
    })
    public Map selectRecharge(Integer page,Integer size){
        List<Map> users = userMapper.selectRecharge(page, size);
        List<Map> maps = userMapper.selectAllRecharge();
        int size1 = maps.size();
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(users);
        jsonResult.put("count",size1);
        return jsonResult.getDataMap();
    }
    @PostMapping("/selectRechargeByTime")
    @ApiOperation("查询返回财务数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time1",value = "第一个时间",required = false),
            @ApiImplicitParam(name = "time2",value = "第二个时间",required = false),
            @ApiImplicitParam(name = "page",value = "页码",required = true),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true)
    })
    public Map selectRechargeByTime(String time1, String time2, Integer page, Integer size) throws Exception {
        List<Map> users = userService.selectRechargeByTime(time1, time2, page, size);
        List<Map> maps = userMapper.selectRechargeByTimeAll(time1, time2);
        int size1 = maps.size();
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(users);
        jsonResult.put("count",size1);
        return jsonResult.getDataMap();
    }
    @PostMapping("/selectOrderAndUser")
    @ApiOperation("返回给前端所有的订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true)
    })
    public Map selectOrderAndUser(Integer page,Integer size) throws Exception {
        List<Map> users = userService.selectOrderAndUser(page, size);
        List<Map> maps = orderMapper.selectOrderAndUserAll();
        int size1 = maps.size();
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(users);
        jsonResult.put("count",size1);
        return jsonResult.getDataMap();
    }
    @PostMapping("/selectOrderAndUserBy")
    @ApiOperation("通过订单编号和交易时间返回查询数据")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "seriaLnNumber",value = "订单编号",required = false),
            @ApiImplicitParam(name = "time1",value = "小的时间",required = false),
            @ApiImplicitParam(name = "time2",value = "大的时间",required = false),
            @ApiImplicitParam(name = "page",value = "页码",required = true),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true)
    })
    public Map selectOrderAndUserBy(String seriaLnNumber, String time1, String time2, Integer page, Integer size) throws Exception {
        List<Map> users = userService.selectOrderAndUserBy(seriaLnNumber, time1, time2, page, size);
        List<Map> maps = orderMapper.selectOrderAndUserByAll(seriaLnNumber, time1, time2);
        int size1 = maps.size();
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(users);
        jsonResult.put("count",size1);
        return jsonResult.getDataMap();
    }
}
